<?php
class userModel extends CI_Model{

	var $tbl = 'users';
	
	public function isExist($col,$val){
		$this->db->where($col,$val);
		$q = $this->get($this->tbl);
		if($q->num_rows()>0)
			return true;
		else
			return false;
	}
	public function login($data){
		$email = $data['email'];
		$password = $data['password'];
		if(!empty($email) && !empty($password)){
			$password = md5($password);

				$this->db->where('email',$email);
				$this->db->where('password',$password);
				$q = $this->db->get($this->tbl);
					if($q->num_rows()>0):
						$this->db->query("update $this->tbl set last_login = now() where email='$email'");
						return true;
					else:
						return false;
					endif;
		}
	}
	
	public function updateLastLogin($email){
		$user = $this->db->query("update $this->tbl set last_login = now() where email='$email'");
		//$data = array('last_login'=>$user->lastlogin);
		//$this->db->where('email',$email);			
		//$this->db->update($this->tbl,$data);
		//$result = $user;
	}
	
	
	public function getUserInfo($col,$val){
		$this->db->where($col,$val);
		$q = $this->db->get($this->tbl);
		if($q->num_rows()>0){
			return $q->result();
		}
		
	}
	
	public function signup($data){
		if(isset($data) && array($data)){
		$this->db->insert($this->tbl,$data);
		return true;
		}
	}

	
	public function deleteUser($id){
		if(isset($id) && !empty($id)){
			$this->db->where('id',$id);
			$this->db->delete($this->tbl);
			return true;
		}
	}

}